home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / utilities / exdat100.lha / xd / xd.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-28  |  7.4 KB  |  291 lines

  1. /* Copyright © 1994 Cedric Beust. See file COPYRIGHT for more information */
  2. /* 
  3.  * xd.h
  4.  *
  5.  * $Id: xd.h,v 1.7 1994/01/27 22:13:40 beust Exp beust $
  6.  */
  7.  
  8. /*
  9.  ** Main include for the ExtData package.
  10.  ** Functions start with xd_
  11.  ** Types start with Xd_
  12.  */
  13.  
  14. static char *version = "\0$VER: version 1.00 (27-01-94)";
  15.  
  16. /*===========================================================================
  17.  ** Includes
  18.  */
  19.  
  20. /* Prototypes */
  21. #include <clib/iffparse_protos.h>
  22. #include <clib/dos_protos.h>
  23. #include <clib/exec_protos.h>
  24. #include <clib/alib_protos.h>
  25.  
  26. /* Libraries definition */
  27. #include <libraries/iffparse.h>
  28.  
  29. #include <exec/lists.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32.  
  33. /*===========================================================================
  34.  ** Types
  35.  */
  36.  
  37.           /* Flags for xd_Open() */
  38. typedef enum { XD_READ, XD_WRITE }
  39.  
  40.                 Xd_Mode;
  41.  
  42.           /* Flags for xd_DeclareType() */
  43. typedef enum { XD_UNKNOWN_TYPE, XD_STRING, XD_INTEGER}
  44.  
  45.                 Xd_Type; 
  46.  
  47.           /* The main type */
  48. typedef struct _Xd_Database
  49.  
  50.                 *Xd_Database;
  51.  
  52.  
  53.           /* The possible errors */
  54. typedef enum {
  55.    XD_FIELD_ALREADY_EXISTS = 1,
  56.    XD_NO_TYPE_XSHA = 2,
  57.    XD_NO_ID_XINF = 3,
  58.    XD_NO_ID_XFIE = 4,
  59.    XD_NO_ID_XUSE = 5,
  60.    XD_NO_IFFPARSE = 6,
  61.    XD_NO_FILE_READ = 7,
  62.    XD_NO_ALLOC_IFF = 8,
  63.    XD_NO_VALID_FILETYPE = 9,
  64.    XD_NO_OPENIFF_READ = 10,
  65.    XD_NO_OPENIFF_WRITE = 11,
  66.    XD_NO_NEW_FIELD_ALLOWED = 12,
  67.    XD_UNKNOWN_FIELD_TYPE = 13,
  68.    XD_UNKNOWN_FIELD = 14,
  69.    XD_NO_TYPE_XCON = 15,
  70. }
  71.  
  72.                 *Xd_Error;
  73.  
  74. /*===========================================================================
  75.  ** Function prototypes
  76.  */
  77.  
  78. /*----------------------------------------------------------------------
  79.  ** xd_Init
  80.  ** Initialize xd. Must be called before using any other function
  81.  ** Return 0 if successful.
  82.  */
  83. int
  84. xd_Init(void);
  85.  
  86.  
  87. /*---------------------------------------------------------------------------
  88.  ** xd_Uninit
  89.  ** Close xd and free its resources
  90.  */
  91. void
  92. xd_Uninit(Xd_Database xd);
  93.  
  94.  
  95. /*---------------------------------------------------------------------------
  96.  ** xd_Open
  97.  ** Open a file in XD_READ or XD_WRITE mode.
  98.  ** fileType is the type of this file. In XD_WRITE mode, it will
  99.  ** be written to the file. In XD_READ mode, it will be compared to the
  100.  ** one read in the file and xd_Open will fail if both strings do not
  101.  ** match exactly. fileType must be non NULL and non empty, or xd_Open will
  102.  ** fail.
  103.  ** Return descriptor of the xd base or NULL if an error occured.
  104.  */
  105. Xd_Database
  106. xd_Open(char *filename, Xd_Mode mode, char *fileType);
  107.  
  108.  
  109. /*---------------------------------------------------------------------------
  110.  ** xd_Close
  111.  ** Close the file
  112.  */
  113. void
  114. xd_Close(Xd_Database xd);
  115.  
  116.  
  117. /*---------------------------------------------------------------------------
  118.  ** xd_ErrorCode
  119.  ** Return the error code of latest function.
  120.  */
  121. Xd_Error
  122. xd_ErrorCode(Xd_Database xd);
  123.  
  124.  
  125. /*---------------------------------------------------------------------------
  126.  ** xd_ErrorString
  127.  ** Return the error string of latest function. This string is a pointer in
  128.  ** my internal space, do NOT free it or alter it.
  129.  */
  130. char *
  131. xd_ErrorString(Xd_Database xd);
  132.  
  133.  
  134. /*---------------------------------------------------------------------------
  135.  ** xd_DeclareAuthor
  136.  ** Declare the author of this file
  137.  */
  138. void
  139. xd_DeclareAuthor(Xd_Database xd, char *author);
  140.  
  141.  
  142. /*---------------------------------------------------------------------------
  143.  ** xd_DeclareApplication
  144.  ** Declare the application for this file
  145.  */
  146. void
  147. xd_DeclareApplication(Xd_Database xd, char *application);
  148.  
  149.  
  150. /*---------------------------------------------------------------------------
  151.  ** xd_DeclareVersion
  152.  ** Declare the version of this file (or the program that can read it)
  153.  */
  154. void
  155. xd_DeclareVersion(Xd_Database xd, char *version);
  156.  
  157.  
  158. /*---------------------------------------------------------------------------
  159.  ** xd_DeclareDate
  160.  ** Declare the date for this file
  161.  */
  162. void
  163. xd_DeclareDate(Xd_Database xd, char *date);
  164.  
  165.  
  166. /*---------------------------------------------------------------------------
  167.  ** xd_ReadType
  168.  ** Return : the type this file (this is a pointer to my
  169.  ** internal space, do NOT alter it or free it)
  170.  */
  171. char *
  172. xd_ReadType(Xd_Database xd);
  173.  
  174.  
  175. /*---------------------------------------------------------------------------
  176.  ** xd_ReadApplication
  177.  ** Return : the application name of this file (this is a pointer to my
  178.  ** internal space, do NOT alter it or free it)
  179.  */
  180. char *
  181. xd_ReadApplication(Xd_Database xd);
  182.  
  183.  
  184. /*---------------------------------------------------------------------------
  185.  ** xd_ReadAuthor
  186.  ** Return : the author of this file (this is a pointer to my
  187.  ** internal space, do NOT alter it or free it)
  188.  */
  189. char *
  190. xd_ReadAuthor(Xd_Database xd);
  191.  
  192.  
  193. /*---------------------------------------------------------------------------
  194.  ** xd_ReadDate
  195.  ** Return : the date of this file (this is a pointer to my
  196.  ** internal space, do NOT alter it or free it)
  197.  */
  198. char *
  199. xd_ReadDate(Xd_Database xd);
  200.  
  201.  
  202. /*---------------------------------------------------------------------------
  203.  ** xd_ReadVersion
  204.  ** Return : the version of this file (this is a pointer to my
  205.  ** internal space, do NOT alter it or free it)
  206.  */
  207. char *
  208. xd_ReadVersion(Xd_Database xd);
  209.  
  210.  
  211. /*---------------------------------------------------------------------------
  212.  ** xd_DeclareSharedString
  213.  ** Declare a pair key/value into the common pool of the file
  214.  */
  215. void
  216. xd_DeclareSharedString(Xd_Database xd, char *field, char *value);
  217.  
  218.  
  219. /*---------------------------------------------------------------------------
  220.  ** xd_ReadSharedString
  221.  ** Fill the value associated to the key in the common part
  222.  ** of the file. *value will contain a pointer to our internal
  223.  ** structure. Do NOT free it, or alter it. If this shared string
  224.  ** doesn't exist, *value will contain NULL
  225.  */
  226. void
  227. xd_ReadSharedString(Xd_Database xd, char *key, char **value);
  228.  
  229.  
  230. /*---------------------------------------------------------------------------
  231.  ** xd_DeclareField
  232.  ** Declare a new field and its type (XD_INTEGER, XD_STRING, ...)
  233.  ** Return 0 if successful.
  234.  */
  235. int
  236. xd_DeclareField(Xd_Database xd, char *field, Xd_Type type);
  237.  
  238.  
  239. /*---------------------------------------------------------------------------
  240.  ** xd_AssignField
  241.  ** Assign the given field with the value
  242.  */
  243. void
  244. xd_AssignField(Xd_Database xd, char *field, void *value);
  245.  
  246.  
  247. /*---------------------------------------------------------------------------
  248.  ** xd_WriteRecord
  249.  ** Write to the file the record as it is so far
  250.  */
  251. void
  252. xd_WriteRecord(Xd_Database xd);
  253.  
  254.  
  255. /*---------------------------------------------------------------------------
  256.  ** xd_NextRecord
  257.  ** Skip to next record in database xd
  258.  ** Return 0 if EOF reached
  259.  */
  260. int
  261. xd_NextRecord(Xd_Database xd);
  262.  
  263.  
  264. /*---------------------------------------------------------------------------
  265.  ** xd_EndOfFile
  266.  ** Return 1 if the end of file is reached, 0 otherwise
  267.  */
  268. int
  269. xd_EndOfFile(Xd_Database xd);
  270.  
  271.  
  272. /*---------------------------------------------------------------------------
  273.  ** xd_ReadField
  274.  ** Read a field into the variable dest
  275.  ** If type == STRING, this function will allocate a string to hold the
  276.  ** result. The returned value must be freed with xd_Free()
  277.  ** Return 1 if the field doesn't exist
  278.  */
  279. int
  280. xd_ReadField(Xd_Database xd, char *field, Xd_Type type, void *dest);
  281.  
  282.  
  283. /*---------------------------------------------------------------------------
  284.  ** xd_Free
  285.  ** Free a variable prealably allocated by xd
  286.  */
  287. void
  288. xd_Free(void *var);
  289.  
  290.  
  291.